﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MODEL;

namespace StudentManage
{
    public partial class Frm_Student : Form
    {
        public Frm_Student()
        {
            InitializeComponent();
        }
        DataGridView dgv1;
        public Frm_Student(DataGridView dgv1)
        {
            InitializeComponent();
            this.dgv1 = dgv1;
        }

        //添加
        private void button2_Click(object sender, EventArgs e)
        {
            StuCard stuInfo = new StuCard();

            stuInfo.StuId = this.txt_StuId.Text;
            stuInfo.StuName = txt_StuName.Text;
            if (radioButton1.Checked==true)
            {
                stuInfo.StuSex = radioButton1.Text;
            }
            else
            {
                stuInfo.StuSex = radioButton2.Text;
            }
            
            stuInfo.StuCardId = this.label5.Text;
          
            try
            { 
                //执行添加方法，返回受影响行数
                int num = BLL.StuCardManage.StuCardService.Add(stuInfo);
                if (num > 0)
                {
                    MessageBox.Show("操作成功");

                    this.Close();
                    dgv1.DataSource = BLL.StuCardManage.StuCardService.ChaXunStudent();
                    //Frm_List.listBox1.Items.Add($"修改学号为：{dgv1.SelectedRows[0].Cells["StuId"].Value.ToString()} 的学生信息，操作成功");

                }
                else
                {
                    MessageBox.Show("操作失败");
                    //Frm_List.listBox1.Items.Add($"修改学号为：{dgv1.SelectedRows[0].Cells["StuId"].Value.ToString()} 的学生信息，操作失败");
                }
            }
            catch (Exception ex)
            {
                //显示错误信息
                MessageBox.Show(ex.Message);
                //Frm_List.listBox1.Items.Add("执行操作时出现问题:\t\n" + ex.Message);
            }
        }
        private void btn_Update_Click(object sender, EventArgs e)
        {


        }

        private void Frm_Student_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            byte[] data = new byte[12];
            if (HPITRFID.EPCSDKHelper.IdentifySingleTag(Frm_Main.handle, data, null, 0) == true)
            {

                this.label5.Text = HPITRFID.ConvertHelper.ByteArrayToHexString(data);
                MessageBox.Show("读取成功");
            }
            else
                MessageBox.Show("读取失败");
            //Frm_List.listBox1.Items.Add("读取失败");
        }
    }
}
